package com.jxinternet.platform.services.coder;

import com.google.protobuf.InvalidProtocolBufferException;
import com.google.protobuf.MessageLite;
import com.jxinternet.platform.services.entity.protobuf.BattleProtos;
import com.jxinternet.platform.services.entity.protobuf.LoginProtos;
import com.jxinternet.platform.services.entity.protobuf.RegisterProtos;
import com.jxinternet.platform.services.entity.protobuf.SocketModelProtos;
import com.jxinternet.platform.services.protocol.BaseProtocol;

/**
 * 解码器2
 * 解第二层
 * Created by gold-jx on 2017/6/17.
 */
public class MessageDecoder {

    public MessageLite toDecode(SocketModelProtos.SocketModelRequest socketModel) throws InvalidProtocolBufferException {

        byte[] bytes = socketModel.getData().toByteArray();

        //byte[]  new_bts= Arrays.copyOfRange(bytes, 4, bytes.length);

        switch (socketModel.getCmd()) {
            case BaseProtocol.Area_Login:
                LoginProtos.LoginRequest loginRequest = LoginProtos.LoginRequest.parseFrom(bytes);
                return loginRequest;
            case BaseProtocol.Area_User_Register:
                RegisterProtos.RegisterRequest registerRequest = RegisterProtos.RegisterRequest.parseFrom(bytes);
                return registerRequest;
            case BaseProtocol.Area_Battle:
                BattleProtos.BattleRequest battleRequest = BattleProtos.BattleRequest.parseFrom(bytes);
                return battleRequest;
            default:
                break;
        }

        return null;


    }

}